package com.cskaoyan;

import com.cskaoyan.jdbc.util.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/06/02 11:21
 *
 * @author ciggar
 */
public class ExecuteDemo {

    public static void main(String[] args) throws SQLException {

        // 获取连接
        Connection connection = JDBCUtils.getConnection();

        // 获取statement对象
        Statement statement = connection.createStatement();


        // 执行SQL语句
        boolean ret = statement.execute("select * from city");
        System.out.println(ret);
        if (ret) {

            System.out.println("执行了查询方法");

        }else {
            System.out.println("执行了增删改方法");
        }

        // 获取结果集
        ResultSet resultSet = statement.getResultSet();
//        int updateCount = statement.getUpdateCount();

        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");

            System.out.println("id:" + id + ", name:" + name);

        }

        // 关闭资源
        JDBCUtils.close(resultSet,statement,connection);


    }
}
